//
//  SHTextFieldCell.m
//  NEWHYSJ
//
//  Created by SH_iOS on 2017/5/9.
//  Copyright © 2017年 SH. All rights reserved.
//

#import "SHTextFieldCell.h"
@interface SHTextFieldCell()<UITextFieldDelegate>

@end
@implementation SHTextFieldCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self configUI];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
    
}

- (void)configUI{
    self.nameLabel = [[UILabel alloc]init];
    self.nameLabel.font = KSHSystemFont(15);
    [self addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(__I6Width(15));
        make.centerY.mas_equalTo(self.mas_centerY);
        make.width.mas_equalTo(__I6Width(100));
        make.height.mas_equalTo(__I6Height(20));
    }];
    
    self.contentTf = [[UITextField alloc]init];
    self.contentTf.font = KSHSystemFont(15);
    self.contentTf.delegate = self;
    self.contentTf.returnKeyType = UIReturnKeyDone;
    self.contentTf.clearButtonMode = UITextFieldViewModeAlways;
    [self addSubview:self.contentTf];
    [self.contentTf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).with.offset(__I6Width(15));
        make.centerY.mas_equalTo(self.mas_centerY);
        make.right.equalTo(self.mas_right).with.offset(__I6Width(-15));
        make.height.mas_equalTo(__I6Height(20));
    }];
    
    UIView *line  = [[UIView alloc]init];
    line.backgroundColor  = KLINECOLOR;
    [self addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(__I6Width(15));
        make.bottom.equalTo(self.mas_bottom);
        make.width.mas_equalTo(KScreenWidth);
        make.height.mas_equalTo(0.5);
    }];


}
- (void)setLabelText:(NSString *)labelText{
    
    CGFloat w = [SHHelper widthOfString:labelText font:KSystemFont(15) height:__I6Height(20)];

    CGFloat labelW  =  w > __I6Width(80) ? __I6Width(100) : __I6Width(80);
    if ([labelText isEqualToString:@"转账金额"] ||[labelText isEqualToString:@"汇款人姓名"] || [labelText isEqualToString:@"汇款账号后5位"] ) {
        labelW = __I6Width(130) ;
    }
    [self.nameLabel mas_updateConstraints:^(MASConstraintMaker *make){
        make.left.equalTo(self.mas_left).with.offset(__I6Width(15));
        make.top.equalTo(self.mas_top).with.offset(__I6Height(11));
        make.width.mas_equalTo(labelW);
        make.height.mas_equalTo(__I6Height(20));
        
    }];
    self.nameLabel.text = labelText;
    [self.contentTf mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).with.offset(__I6Width(15));
        make.centerY.mas_equalTo(self.mas_centerY);
        make.right.equalTo(self.mas_right).with.offset(__I6Width(-15));
        make.height.mas_equalTo(__I6Height(40));
    }];
    
}
- (void)setPlaceholder:(NSString *)placeholder{
    self.contentTf.placeholder  = placeholder;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}
-(void)textFieldDidEndEditing:(UITextField *)textField{
    [Tool setObject:textField.text forKey:self.nameLabel.text];
}

@end
